package com.heima.controller;

import com.heima.pojo.domain.PageResult;
import com.heima.pojo.dto.OrderPageQueryDto;
import com.heima.service.OrderService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDateTime;

@RestController
@RequestMapping("/api/order-service")
public  class ReportController {

    @Autowired
    private OrderService orderService;

    /**
     * 根据时间差订单总数
     * @param start
     * @param end
     * @return
     */
    @GetMapping("/report/orderCount")
    public Integer orderCount(@RequestParam @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") LocalDateTime start,
                              @RequestParam @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") LocalDateTime end){
        return orderService.searchOrderCount(start,end);
    }

    /**
     * 根据时间查订单总销售额
     * @param start
     * @param end
     * @return
     */
    @GetMapping("/report/orderAmount")
    public Integer orderAmount(@RequestParam @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") LocalDateTime start,
                               @RequestParam @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") LocalDateTime end){
        return orderService.searchOrderAmount(start,end);
    }


    /**
     * 根据
     * @param oDto
     * @return
     */

    @GetMapping("/order/search")
    public PageResult searchOrder(OrderPageQueryDto oDto){
        return  orderService.searchOrder(oDto);
    }
}
